/***************************************************************************
 * Copyright 2012-2013 TXT e-solutions SpA
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * This work was performed within the IoT_at_Work Project
 * and partially funded by the European Commission's
 * 7th Framework Programme under the contract ICT-257367.
 *
 * Authors:
 *      Salvatore Piccione (TXT e-solutions SpA)
 *
 * Contributors:
 *        Domenico Rotondi (TXT e-solutions SpA)
 **************************************************************************/
package it.txt.ens.client.core;

import it.txt.ens.client.exception.ENSClientException;
import it.txt.ens.core.ENSResource;
import it.txt.ens.core.exception.ENSConnectionException;


/**
 * This interface represents an Event Notification Service (ENS) Client. It defines the two operations
 * commons to all kinds of client (i.e. publisher and subscriber):
 * <ul><li>{@link #connect()}</li><li>{@link #disconnect()}</li></ul>.
 * 
 * @author Salvatore Piccione (TXT e-solutions SpA - salvatore.piccione AT txtgroup.com)
 * @author Domenico Rotondi (TXT e-solutions SpA - domenico.rotondi AT txtgroup.com)
 *
 */
public interface ENSClient {
    /**
     * Sets up a communication session between this client and the ENS.<br/>
     * The setting up envisages the following steps:
     * <ol><li>retrieval of the best suitable authorising capability token (i.e. the capability token granting the least 
     * privileges required to perform the requested operation)</li>
     * <li>retrieval of the X.509 certificate of the service requestor</li>
     * <li>preparation of the digitally signed service request (it contains also the authorising capability)</li>
     * <li>submission of the service request to the Access Request Broker</li>
     * <li>consumption of the service response sent by the ENS Authorisation Service</li></ol>
     * If no exception has been thrown, the client is authorised to connect to the operative broker
     * reported in the ENS Authorisation Service's response and a session is started.
     * @throws ENSConnectionException if an error happens while setting up the session
     * @throws ENSClientException if an error happens while retrieving the best suitable authorising capability,
     */
    public void connect () throws ENSClientException, ENSConnectionException;
    
    /**
     * Quits the communication session between this client and the ENS.<br/>
     */
    public void disconnect ();
    
    /**
     * States if this client is connected to the ENS (i.e. the session is alive).
     * 
     * @return <code>true</code> is the client is connected to the ENS,
     * <code>false</code> otherwise.
     */
    public boolean isConnected ();
    
    /**
     * Returns the resource this client is connected to.
     * 
     * @return the resource this client is connected to.
     */
    public ENSResource getTargetResource ();
}
